function hideorderinfo(){
	if($("#orderlistpanel").length>0){
		$("#orderinfopanel").addClass("hide");
		$("#orderlistpanel").removeClass("hide");
	}else window.location.href=ctx+"/order/orderlist";
}

function shouhuo(ordercode,obj){
	$w.openWin({html:"<div style='text-align:center;padding:40px 0px;'><p style='font-size:16px;'>确定已收货？</p><p style='margin-top:20px'><a href='javascript:okshouhuo(\""+ordercode+"\");' class='btn green marginR16'>确 定</a><a href='javascript:$w.closeCurrWin();' class='btn'>取 消</a></p></div>",title:'确认收货提示',w:500,h:220,modal:true,minimizable:false,maximizable:false,collapsible:false,afterClose:function(re){
		if(re){
			hideorderinfo();
			$("#status"+ordercode).text("交易完成");
			$(obj).parent().html('<a href="javascript:tuoihuo(\''+ordercode+'\');">申请退货</a>');
			window.location.reload();
		}
	}});
}
function okshouhuo(ordercode){
	$w.httpRequest({
		url:ctx+"/order/receiptGoods",
		data:{"ordercode":ordercode},
		ok:function(){
			$w.closeCurrWin('ok');
		}
	})
}
function tuoihuo(ordercode){
	window.location.href=ctx+"/order/showbackwrite?ordercode="+ordercode;
}
function addOften(pid,obj){
    $w.httpRequest({
        url: apiroot + "/order/addOften",
        data: {"priceid": pid},
        ok: function (ret) {
            $(obj).text("已加入常购清单");
        }
    })
}
function addToCart(pid){
    var url=ctx+"/order/addToCart?pid="+pid+"&amount=1";
    // window.open(url);
	$w.addtocart(url);
}
function cancelorder(ordercode){
	if(confirm("确定取消订单？")){
		$w.httpRequest({
			url:apiroot+"/order/cancelorder",
			data:{"ordercode":ordercode},
			ok:function(ret){
				window.location.reload();
			}
		})
	}
}
function buyagain(ordercode){
	$w.httpRequest({
		url:apiroot+"/order/generateorder2",
		data:{"data":ordercode,"type":"orderbuyagain"},
		ok:function(ret){
			var ordercode=ret.Data;
			window.location.href=ctx+"/order/orderconfirm?ordercode="+ordercode;
		},fail:function(ret){
			if(ret.MsgCode=='101'){
				var h="以下商品库存不足：";
				var list=window.eval(ret.MsgDesc);
				for(var i=0;i<list.length;i++){
					h+="\r\n"+(i+1)+"、"+(list[i].productname || list[i].name)+(list[i].attrname || '');
				}
				alert(h);
			}else if(ret.MsgCode=='102'){
				var h="以下商品已下架：";
				var list=window.eval(ret.MsgDesc);
				for(var i=0;i<list.length;i++){
					h+="\r\n"+(i+1)+"、"+(list[i].productname || list[i].name)+(list[i].attrname || '');
				}
				alert(h);
			}else if(ret.MsgCode=='103'){
				var h="以下商品已不在您的可购范围：";
				var list=window.eval(ret.MsgDesc);
				for(var i=0;i<list.length;i++){
					h+="\r\n"+(i+1)+"、"+(list[i].productname || list[i].name)+(list[i].attrname || '');
				}
				alert(h);
			}else if(ret.MsgCode=='4001') {
                var h="以下商品超出限买次数：";
                var list=window.eval(ret.MsgDesc);
                for(var i=0;i<list.length;i++){
                    h+="\r\n"+(i+1)+"、"+(list[i].productname || list[i].name)+(list[i].attrname || '');
                }
                alert(h);
			}else if(ret.MsgCode='4010'){
                var h="促销库存不足：";
                var list=window.eval(ret.MsgDesc);
                for(var i=0;i<list.length;i++){
                    h+="\r\n"+(i+1)+"、"+(list[i].productname || list[i].name)+(list[i].attrname || '');
                }
                alert(h);
			}else alert(ret.MsgDesc);
			return false;
		}
	})
}